package leecode

import "sort"

type SortedStack struct {
	stack []int
}

func ConstructorM05() SortedStack {
	return SortedStack{
		stack: make([]int, 0),
	}
}

func (this *SortedStack) Push(val int) {
	this.stack = append(this.stack, val)
	sort.Slice(this.stack, func(i, j int) bool {
		return this.stack[i] > this.stack[j]
	})
}

func (this *SortedStack) Pop() {
	if len(this.stack) == 0 {
		return
	}
	//删除栈顶元素
	this.stack = this.stack[:len(this.stack)-1]
}

func (this *SortedStack) Peek() int {
	if len(this.stack) == 0 {
		return -1
	}
	return this.stack[len(this.stack)-1]
}

func (this *SortedStack) IsEmpty() bool {
	return len(this.stack) == 0
}
